<template>
	<!-- 抽屉式  -->
	<el-drawer title="新增招聘信息" size="50%" :visible.sync="dialog" :before-close="handleClose" direction="rtl" custom-class="demo-drawer"
	 ref="drawer">
		<div class="demo-drawer__content" align="left">
			<el-form ref="form" :model="form" label-width="80px" :rules="rules">

				<el-form-item label="招聘部门" prop="name">
					<el-select v-model="form.name" placeholder="...请选择">
					  <el-option v-for="dept in deptName" :label="dept" :value="dept" :key="dept"></el-option>
					</el-select>
				</el-form-item>
				
				<el-form-item label="学历背景" prop="edaBg">
				  <el-radio-group v-model="form.edaBg">
				    <el-radio v-for="edu in eduBgs" :label="edu" :value="edu" :key="edu">{{edu}}</el-radio>
				  </el-radio-group>
				</el-form-item>

				<el-form-item label="招聘需求" prop="campusRecruitment">
					<el-input type="textarea" v-model="form.campusRecruitment" clearable style="width: 80%;"></el-input>
				</el-form-item>

				<el-form-item label="需求人数" prop="nums">
					<el-input v-model="form.nums" clearable style="width: 80%;"></el-input>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" @click="saveRecruit()">保 存</el-button>
					<el-button @click="reset()">重 置</el-button>
				</el-form-item>
			</el-form>
		</div>

	</el-drawer>
</template>

<script>
	export default {
		data() {

			return {
				form: {
					name: '',
					campusRecruitment: '',
					edaBg: '本科',
					nums:'',
					
				},	
				deptName:[],
				eduBgs:['大专及以下','本科','硕士','博士及以上'],
				//标识职务是否存在所用
				flag: false,
				//表单验证规则
				rules: {
					name: [
					  {required: true,message: '请选择一个部门',trigger: 'change'}
					],
					nums: [
						{required: true,message: '请输入岗位HC',trigger: 'blur'},
						{min: 1,max: 4,message: '长度在 1 到 4 个字符',trigger: 'blur'}
					],
					campusRecruitment: [
						{required: true,message: '内容不能为空',trigger: 'blur'}
					],
				},
				dialog: false,
				loading: false
			}
		},
		methods: {
			saveRecruit() {
				this.$refs.form.validate((valid) => {
					if (valid) {
						const that = this
						this.$http.post("/recruitMeg/saveRecruitInfo", this.form).then(function(res) {
							if (res.data.code == 200) {
								that.$message({
									showClose: true,
									message: "保存成功",
									type: 'success'
								});
								//整个页面进行刷新
								window.location.reload();
							} else {
								that.$message({
									showClose: true,
									message: "保存失败",
									type: 'error'
								});
							}
						})
					} else {
						return false;
					}
				})
			},
			reset() {
				this.$refs.form.resetFields();
			},
			handleClose(done) {
				if (this.loading) {
					return;
				}
				this.$confirm('确定关闭将不会保存数据？')
					.then(_ => {
						this.loading = true;
						this.timer = setTimeout(() => {
							done();
							this.loading = false;
						}, 100);
						this.reset();
					})
					.catch(_ => {});
			}
		},
		created() {
			var that = this
			this.$http.get("/recruitMeg/getDeptName").then(function(res){
			  that.deptName = res.data.deptName;
			})
		}

	}
</script>

<style>

</style>
